<?php


namespace Xiaoguai\DesignPattern\DP012\Flyweight;


use Xiaoguai\DesignPattern\DP012\FlyweightInterface;
use Xiaoguai\DesignPattern\DP012\UnsharedFlyweight;

class Flyweight implements FlyweightInterface
{
    protected $internal_info;

    public function __construct($info)
    {
        $this->internal_info = $info;
    }

    /**
     * 共享的内容通过构造函数初始化共享,非共享的元素在调用的时候通过unsharedFlyweight传入
     * @param UnsharedFlyweight $unsharedFlyweight
     * @return array
     */
    public function operation(UnsharedFlyweight $unsharedFlyweight)
    {
        return [
            'internal' => $this->internal_info,
            'external' => $unsharedFlyweight->getInfo(),
        ];
    }
}